package org.xa3apm.vote.converters;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

import org.xa3apm.vote.hibernate.entities.Candidate;

public class CandidateConverter implements Converter {
	@Override
	public Object getAsObject(FacesContext fContext, UIComponent uiComponent,
			String string) {
		if (string.trim().isEmpty()) {
			return null;
		}
		Candidate candidate = new Candidate();
		candidate.setId(Long.parseLong(string));
		return candidate;
	}

	@Override
	public String getAsString(FacesContext fContext, UIComponent uiComponent,
			Object object) {
		// TODO Auto-generated method stub
		return object.toString();
	}

}
